package com.xiao.method_area;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * 方法区（非堆）内存溢出
 * 方法区
 *
 * @CreateBy 花和尚  1130365579@qq.com  2022/11/15 21:48
 * @Version 1.0
 */
public class JavaMethodAreaOOM {
    /**
     *
     */
    public static void main(String[] args) {
        System.out.println("进入程序");
        while (true) {
            // CGLib 字节码技术
            Enhancer enhancer = new Enhancer(); // CGLib 代理 proxy
            enhancer.setSuperclass(OOMObject.class);
            enhancer.setUseCache(false);
            enhancer.setCallback(new MethodInterceptor() {
                @Override
                public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
                    return methodProxy.invokeSuper(o, args);
                }
            });
        }
    }

    static class OOMObject {
    }
}
